package musicstore.com.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.net.httpserver.Filter.Chain;

import musicstore.com.dao.UserDao;
import musicstore.com.dao.impl.UserDaoImpl;
import musicstore.com.entity.User;

public class FilterLoginServlet extends HttpServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		
		UserDao dao = new UserDaoImpl();
		User user = dao.checkUser(username, password);
		
		if(user!=null){
			request.setAttribute("user", user);
			response.sendRedirect("LoginSuccess.jsp");
		}else{
			request.setAttribute("error", "用户名或密码错误");
			request.getRequestDispatcher("FilterLogin.jsp").forward(request, response);
		}
	}

}
